Add tests for "build --all"
authorSebastian Dröge <sebastian@centricular.com>
Sat, 7 Jan 2017 11:01:39 +0000 (13:01 +0200)
committerSebastian Dröge <sebastian@centricular.com>
Sun, 8 Jan 2017 12:02:58 +0000 (14:02 +0200)
These are basically the same as the ones from "test --all"

tests/build.rs

index 4ab8706cebb635317f3cbdc3c0668838f99d41d0..8959fac7e1b25d979e1a238ecee0b14fd21e99ea 100644 (file)
@@ -12,6 +12,7 @@ use cargotest::{is_nightly, rustc_host, sleep_ms};
 use cargotest::support::paths::{CargoPathExt,root};
 use cargotest::support::{ProjectBuilder};
 use cargotest::support::{project, execs, main_file, basic_bin_manifest};
+use cargotest::support::registry::Package;
 use hamcrest::{assert_that, existing_file, is_not};
 use tempdir::TempDir;
 
@@ -2554,3 +2555,103 @@ fn cargo_build_empty_target() {
                 execs().with_status(101)
                 .with_stderr_contains("[..] target was empty"));
 }
+
+#[test]
+fn build_all_workspace() {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [project]
+            name = "foo"
+            version = "0.1.0"
+
+            [dependencies]
+            bar = { path = "bar" }
+
+            [workspace]
+        "#)
+        .file("src/main.rs", r#"
+            fn main() {}
+        "#)
+        .file("bar/Cargo.toml", r#"
+            [project]
+            name = "bar"
+            version = "0.1.0"
+        "#)
+        .file("bar/src/lib.rs", r#"
+            pub fn bar() {}
+        "#);
+    p.build();
+
+    assert_that(p.cargo_process("build")
+                 .arg("--all"),
+                execs().with_stderr("[..] Compiling bar v0.1.0 ([..])\n\
+                       [..] Compiling foo v0.1.0 ([..])\n\
+                       [..] Finished debug [unoptimized + debuginfo] target(s) in [..]\n"));
+}
+
+#[test]
+fn build_all_virtual_manifest() {
+    let p = project("workspace")
+        .file("Cargo.toml", r#"
+            [workspace]
+            members = ["foo", "bar"]
+        "#)
+        .file("foo/Cargo.toml", r#"
+            [project]
+            name = "foo"
+            version = "0.1.0"
+        "#)
+        .file("foo/src/lib.rs", r#"
+            pub fn foo() {}
+        "#)
+        .file("bar/Cargo.toml", r#"
+            [project]
+            name = "bar"
+            version = "0.1.0"
+        "#)
+        .file("bar/src/lib.rs", r#"
+            pub fn bar() {}
+        "#);
+    p.build();
+
+    // The order in which foo and bar are built is not guaranteed
+    assert_that(p.cargo_process("build")
+                 .arg("--all"),
+                execs().with_stderr_contains("[..] Compiling bar v0.1.0 ([..])")
+                       .with_stderr_contains("[..] Compiling foo v0.1.0 ([..])")
+                       .with_stderr("[..] Compiling [..] v0.1.0 ([..])\n\
+                       [..] Compiling [..] v0.1.0 ([..])\n\
+                       [..] Finished debug [unoptimized + debuginfo] target(s) in [..]\n"));
+}
+
+#[test]
+fn build_all_member_dependency_same_name() {
+    let p = project("workspace")
+        .file("Cargo.toml", r#"
+            [workspace]
+            members = ["a"]
+        "#)
+        .file("a/Cargo.toml", r#"
+            [project]
+            name = "a"
+            version = "0.1.0"
+
+            [dependencies]
+            a = "0.1.0"
+        "#)
+        .file("a/src/lib.rs", r#"
+            pub fn a() {}
+        "#);
+    p.build();
+
+    Package::new("a", "0.1.0").publish();
+
+    assert_that(p.cargo_process("build")
+                 .arg("--all"),
+                execs().with_stderr("[..] Updating registry `[..]`\n\
+                       [..] Downloading a v0.1.0 ([..])\n\
+                       [..] Compiling a v0.1.0\n\
+                       [..] Compiling a v0.1.0 ([..])\n\
+                       [..] Finished debug [unoptimized + debuginfo] target(s) in [..]\n"));
+}
+